/* sfacct02.p - CREATE GLTW_DET RECORDS FOR OPERATION ACCOUNTING REPORT  */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.          */
/* $Id:: sfacct02.p 2366 2010-11-10 01:47:19Z zzh                          $: */
/* REVISION: 7.3            CREATED: 02/09/96   BY: rvw *G1MW*           */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Vijaya Pakala */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* myb           */
/* Revision: 1.6        BY: Katie Hilbert      DATE: 04/05/01  ECO: *P008*   */
/* Revision: 1.7        BY: Vandna Rohira      DATE: 07/10/01  ECO: *M1DM*   */
/* Revision: 1.9        BY: Paul Donnelly (SB) DATE: 06/28/03  ECO: *Q00L*   */
/* Revision: 1.11     BY: Jean Miller        DATE: 02/20/08    ECO: *R0NK*   */
/* $Revision: 1.12 $    BY: Huaping Luo        DATE: 03/08/10  ECO: *R22T*   */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* FOR IMPROVEMENT IN PERFORMANCE:                             */
/* 1. CREATING TEMP-TABLE tt_glt_wkfl INSTEAD OF gltw_wkfl.    */
/* 2. CHANGING FIND STATEMENTS WITH NO-LOCK TO FOR FIRST WITH  */
/*    FIELD LIST ATTACHED                                      */
/* 3. USING BUFFERS opgl_det and opgl_hist                     */

{us/bbi/mfdeclre.i}

define parameter buffer opgl_det for opgl_det.
define parameter buffer op_hist  for op_hist.

/* TEMP-TABLE DEFINITION OF tt_gltw_wkfl */
{us/sf/sfgltwdf.i}

/* get periodic costing control file */
find first pcsc_ctrl no-lock where pcsc_domain = global_domain
   no-error.


create tt_gltw_wkfl.
assign
   tt_gltw_acct    = opgl_dr_acct
   tt_gltw_sub     = opgl_dr_sub
   tt_gltw_cc      = opgl_dr_cc
   tt_gltw_project = opgl_dr_proj
   tt_gltw_date    = op_tran_date
   tt_gltw_effdate = op_date
   tt_gltw_desc    = op_wo_nbr + " " +
                     op_wo_lot + " " +
                     string(op_wo_op)
   tt_gltw_amt     = opgl_gl_amt.

/* CALLING PROCEDURE get-entity TO OBTAIN */
/* THE ENTITY VALUE FOR DEBIT LINE        */

run get-entity
   (input  opgl_gl_ref,
    input  opgl_dr_line,
    output tt_gltw_entity).

/* if tt_gltw_entity is blank and periodic costing is enabled,
 * get site entity*/
if available pcsc_ctrl and
   pcsc_ctrl.pcsc_enable = yes and
   tt_gltw_entity = "" then
   for first si_mstr no-lock where
      si_domain = global_domain and
      si_site = op_hist.op_site:
      assign tt_gltw_entity = si_entity.
   end.


create tt_gltw_wkfl.
assign
   tt_gltw_acct    = opgl_cr_acct
   tt_gltw_sub     = opgl_cr_sub
   tt_gltw_cc      = opgl_cr_cc
   tt_gltw_project = opgl_cr_proj
   tt_gltw_date    = op_tran_date
   tt_gltw_effdate = op_date
   tt_gltw_desc    = op_wo_nbr + " " +
                     op_wo_lot + " " +
                     string(op_wo_op)
   tt_gltw_amt     = - opgl_gl_amt.

/* CALLING PROCEDURE get-entity TO OBTAIN */
/* THE ENTITY VALUE FOR CREDIT LINE       */

run get-entity
   (input  opgl_gl_ref,
    input  opgl_cr_line,
    output tt_gltw_entity).

/* if tt_gltw_entity is blank and periodic costing is enabled,
 * get site entity*/
if available pcsc_ctrl and
   pcsc_ctrl.pcsc_enable = yes and
   tt_gltw_entity = "" then
   for first si_mstr no-lock where
     si_domain = global_domain and
     si_site = op_hist.op_site:
     assign  tt_gltw_entity = si_entity.
   end.

PROCEDURE get-entity:

define input  parameter p_opgl_ref  like opgl_det.opgl_gl_ref  no-undo.
define input  parameter p_opgl_line like opgl_det.opgl_dr_line no-undo.
define output parameter p_entity    like glt_det.glt_entity no-undo.

define buffer glt_det   for glt_det.

   for first glt_det
      fields( glt_domain glt_entity glt_line glt_ref)
       where glt_det.glt_domain = global_domain
       and  glt_ref  = p_opgl_ref
       and   glt_line = p_opgl_line
   no-lock:
      p_entity = glt_entity.
   end. /* FOR FIRST glt_det */

END PROCEDURE. /* get-entity */
